//
// Created by 11510 on 2024/6/7.
//
#include <iostream>
#include <string.h>
using namespace std;
typedef string String;

/**
 * @brief String的构造
 *
 */
void test0(){
//    String str1;
//    cout << str1 << endl;

    String str2("hello");
    cout << str2 << endl;

    String str3("hello", 3);

    String str4(str2, 1, 3);
    cout << str4 << endl;

    String str5(8, 'a');
    cout << str5 << endl;

    String::iterator it = str2.begin();
    String str6(it, str2.end());
    cout << str6 << endl;

    char arr[6] = "world";
    cout << String(arr, arr +3) << endl;

}

/**
 * @brief String的拼接
 */
void test1(){
    String str1 = "test";
    String str2 = "a";
    cout << str1 + str2 << endl;
}


void test2(){
    string str1("hello");
    printf("%s\n", str1.c_str());

    cout << str1.empty() << endl;
    cout << str1.size() << endl;

    str1.push_back('6');
    str1.push_back('6');
    str1.push_back('6');

    cout << str1 << endl;

    String str2;
//    str2.append(5, 'a');
    str2.append("hello!world!");
    cout << str2 << endl;

}

/***
 * string的查找
 */
void test3(){
    String str1("hello");
    String str2("lo");

    size_t pos = str1.find(str2);
    cout << pos << endl;


    pos = str1.find("el");
    cout << pos << endl;
}

/***
 * string 的遍历
 */
void test4(){
//    方式一
    string str1("hello");
    for (int i = 0; i < str1.size(); ++i) {
//        printf("%c", str1[i]);
    }

//    方式二
    /**
     * 增强for循环，自动完成容器中元素的遍历
     * 如果没有引用，ch就是容器元素的副本
     */
    for(auto &ch : str1){
        /*++ch;*/
    }


//    方式三
    string::iterator it = str1.begin();
    for(;it != str1.end(); it++){
        cout << *it;
    }




}

int main(int argc, char *argv[]){
    test4();
    return 0;
}

